
CURDIR=`pwd`

genfile=$1
if [ "$genfile" == "" ]; then
    genfile=kfconfig.bin
fi

pass=r3ra21a8?321:1adf,2a

#compressfiles="tmp"
#
#for f in $compressfiles; do
#    if [ ! -e $f ]; then
#        echo "File [ $f ] not exist, please check !"
#        exit -1
#    fi
#done

if [ -f $genfile ]; then
    rm $genfile
fi

CRYPTO=openssl
#CRYPTO=polarssl

files=$KFFILES
if [ "$KFFILES" == "" ];then
    files="-T kffiles.conf"
fi

if [ "$CRYPTO" == "openssl" ]; then
    tar -zvcf - $files | openssl des3 -k $pass | dd of=$genfile
elif [ "$CRYPTO" == "polarssl" ]; then
    tar -zvcf $genfile.tmp $files
    polarssl_aescrypt2 0 $genfile.tmp $genfile string:$pass
    rm $genfile.tmp
fi

if [ "$?" == "0" ]; then
    echo "File [ $genfile ] generate success."
fi

exit 0
